<%-- Created by IntelliJ IDEA. --%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<html>
  <head>
    <title></title>
  </head>
  <body>
        <table>
          <tr>
            <th>序号</th>
            <th>姓名</th>
            <th>头像</th>
            <th>操作</th>
          </tr>
          <c:forEach items="${stuList}" var="stu" varStatus="i">
            <tr>
              <td>${i.index + 1}</td>
              <td>${stu.userName}</td>
              <td>${stu.touxiang}</td>
              <td>删除</td>
            </tr>
          </c:forEach>
        </table>
        <div>
          共 页
          第<span id="page"> <c:out value="${param.page}" default="1"></c:out> </span>页
          <button type="button">上一页</button>
          <button type="button" class="nextPage">下一页</button>
          每页
          <select name="pageSize" id="pageSize">
            <option value="10">10</option>
            <option value="20">20</option>
            <option value="50">50</option>
          </select>
        </div>
        <script>
          window.onload = function(){
              var _nbtn = document.querySelector(".nextPage");
              var _pageSize = document.querySelector("#pageSize");
              var _page = document.querySelector("#page");

              _nbtn.addEventListener('click',function(){
                  var page = Number(_page.innerHTML) + 1;
                  var pageSize = Number(_pageSize.value);
                  var href = location.href;
                  var end = href.indexOf("?");
                  end = (end == -1) ? href.length : end;
                  location.href = href.substring(0,end) + "?page=" + page + "&pageSize=" + pageSize;
              });
          }
        </script>
  </body>
</html>